import { DataMap, SVGSetting } from "./type";
import dataMap from './mock/dataMap.json';
import { JSDOM } from 'jsdom';
import * as d3 from 'd3';
import SVGSizer from "./Preprocessors/SVGSizer";
import SVGScaler from "./Preprocessors/SVGScaler";
import { SvgConfig } from "./typeSC";
import ChartCreator from "./SVGElements/ChartCreator";
import MinMaxInfo from "./SVGElements/MinMaxInfo";
import TextCreator from "./SVGElements/TextCreator";

export default class SVGDesigner {
    dataMap: DataMap;
    svgSizer: SVGSizer;
    svgScaler: SVGScaler;

    body: any;
    svg: any;

    
    constructor(svgConfig: SvgConfig) {
        this.dataMap = dataMap;
        // TODO rename
        this.svgSizer = new SVGSizer(svgConfig['svg_elements']);
        this.svgScaler = new SVGScaler(svgConfig['data_source_list'], dataMap);

        const jsdom = new JSDOM();
        this.body = jsdom.window.document.body
        this.svg = d3.select(this.body).append('svg')
            .attr('width', this.svgSizer.width)
            .attr('height', this.svgSizer.height);

        console.log(this.svgSizer)
        for (let settingHorizontal of svgConfig['svg_elements']) {
            for (let setting of settingHorizontal) {
                switch(setting.type) {
                    case 'Chart':
                        const chartCreator = new ChartCreator(this.svg, setting, this.svgSizer, this.svgScaler)

                        chartCreator.draw();

                        break;
                    case 'MinMaxInfo':
                        const minMaxInfo = new MinMaxInfo(this.svg, setting, this.svgSizer, this.svgScaler);

                        minMaxInfo.draw();

                        break;
                    case 'Text':
                        const textCreator = new TextCreator(this.svg, setting, this.svgSizer, this.svgScaler);

                        textCreator.draw();

                        break;
                }
            }
        }
    }
}